package MaintMenu.VenPricingUpdTBLN;

import java.sql.*;

/**
 * Created with IntelliJ IDEA.
 * User: Jason
 * Date: 8/12/13
 * Time: 5:12 PM
 * To change this template use File | Settings | File Templates.
 */
public class updTEMPUOUT2VenColumn {

    String tbl="";
    String pl="";
    String charc="";
    char lastC;
    int totalfiles=1;
    String isCapa="";
    boolean capa;
    String oPL="";
    int pkg=0;
    Double cuft=0.00D;

    String venPartNum="";
    String venPLNum="";
    String venPackage="";
    String venCUFT="";
    String venPrice="";
    String venCapa="";
    String venDNKNum="";


    String venPartNumField="";
    String venPLNumField="";
    String venPackageField="";
    String venCUFTField="";
    String venPriceField="";
    String venCapaField="";
    String venDNKNumField="";

    public updTEMPUOUT2VenColumn(String cat){

        String cateroy=cat;
        String tbl="";
        String tblorg="";
        String tblPost="";
        String pfield="";



        //Categories
        if (cat=="BC") {
            tbl="TBLBCN_TEMPOUT2";
            tblorg="TBLBCN";

        }if (cat=="HF"){
            tbl="TBLHFN_TEMPOUT2";
            tblorg="TBLHFN";

        }if (cat=="OT"){
            tbl="TBLOTN_TEMPOUT2";
            tblorg="TBLOTN";

        }if (cat=="CL"){
            tbl="TBLCLN_TEMPOUT2";
            tblorg="TBLCLN";

        }if (cat=="MR"){
            tbl="TBLMRN_TEMPOUT2";
            tblorg="TBLMRN";

        }if (cat=="LTLI"){
            tbl="tblltn_TEMPOUTLI2";
            tblorg="TBLLTN";
//            tblPost="LI";
//            cat="LT";
        }if (cat=="LTBK"){
            tbl="tblltn_TEMPOUTBK2";
            tblorg="TBLLTN";
//            tblPost="BK";
//            cat="LT";
        }


            //System.out.print("Processing"+totalfiles+"\t\t");


            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                //Connection to Hicksville
                String dataSourceName = "dbLI";
                String dbURL = "jdbc:odbc:" + dataSourceName;
                Connection connection = DriverManager.getConnection(dbURL, "", "");
                Statement stmt1 = connection.createStatement();
                if (cat=="BC" || cat=="OT"){

                    String[] sql = new String[4];
//                    sql[0]="alter table "+tbl+" add column AP_P double)";
//                    sql[1]="alter table "+tbl+" add column YCC_P double)";
                    sql[0]="UPDATE "+tbl+" SET AP_P=GD_P";
                    sql[1]="UPDATE "+tbl+" SET YCC_P=PROTEC_P";
                    sql[2]="alter table "+tbl+" drop column gd_p)";
                    sql[3]="alter table "+tbl+" drop column protec_p)";
                    for (int x=0; x<sql.length;x++){
                        stmt1.executeUpdate(sql[x]);
                    }

                }else if (cat=="HF"){
                    String[] sql = new String[2];
//                    sql[0]="alter table "+tbl+" add column AP_P double)";
                    sql[0]="UPDATE "+tbl+" SET AP_P=GD_P";
                    sql[1]="alter table "+tbl+" drop column gd_p)";
                    for (int x=0; x<sql.length;x++){
                        stmt1.executeUpdate(sql[x]);
                    }


                }
                connection.close();
                stmt1.close();


            }catch (ClassNotFoundException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                //System.out.println("1:"+e);
            } catch (SQLException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                //System.out.println("2:"+e);


        }

    }

}
